package cn.sdormitory.academic.service.impl;

import cn.sdormitory.academic.dao.ClsPracticeInfoDao;
import cn.sdormitory.academic.dao.ClsPracticeResultDao;
import cn.sdormitory.academic.entity.ClsPracticeInfo;
import cn.sdormitory.academic.entity.ClsPracticeResult;
import cn.sdormitory.academic.service.ClsPracticeResultService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.MathContext;
import java.math.RoundingMode;
import java.util.List;

@Service
public class ClsPracticeResultServiceImpl
        extends ServiceImpl<ClsPracticeResultDao, ClsPracticeResult>
        implements ClsPracticeResultService {

    @Autowired
    ClsPracticeInfoDao clsPracticeInfoDao;

    @Autowired
    ClsPracticeResultDao clsPracticeResultDao;

    @Override
    public List<ClsPracticeResult> findListByClsPracticeByInfoId(Long infoId) {
        LambdaQueryWrapper<ClsPracticeResult> wrapper = new LambdaQueryWrapper<ClsPracticeResult>()
                .eq(ClsPracticeResult::getClsPracticeId, infoId);
        List<ClsPracticeResult> clsPracticeResults = clsPracticeResultDao.selectList(wrapper);
        return clsPracticeResults;
    }

    @Override
    @Transactional
    public Boolean enterClsPracticeResult(List<ClsPracticeResult> clsPracticeResults, ClsPracticeInfo clsPracticeInfo) {
        clsPracticeInfo.setId(clsPracticeResults.get(0).getClsPracticeId());
        clsPracticeInfoDao.updateById(clsPracticeInfo);
        this.updateBatchById(clsPracticeResults);
        return true;
    }
}
